package znbkTopicType;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.lancooznbk.R;

/**
 * Created by Administrator on 2018\3\9 0009.
 */

public class PopupWindowKnowledgePoint extends PopupWindow{

//    private View mainView;
//
//
//    public PopupWindowKnowledgePoint(Context mContext,int width,int height){
//
//        super(mContext);
//        //窗口布局
//        mainView = LayoutInflater.from(mContext).inflate(R.layout.znbk_pop_knowledge_point, null);
////        //分享布局
////        rLayoutDictionary = ((RelativeLayout) mainView.findViewById(R.id.layout_dictionary));
////        //复制布局
////        rLayoutDifficultQuestion = (RelativeLayout) mainView.findViewById(R.id.layout_difficult_question);
//
////        //设置每个子布局的事件监听器
////        if (paramOnClickListener != null){
////            rLayoutDictionary.setOnClickListener(paramOnClickListener);
////            rLayoutDifficultQuestion.setOnClickListener(paramOnClickListener);
////        }
//
//
////        setContentView(mainView);
//        //设置宽度
//        setWidth(width);
//        //设置高度
//        setHeight(height);
////        //设置显示隐藏动画
////        setAnimationStyle(R.style.AnimTools);
////        //设置背景透明
////        setBackgroundDrawable(new ColorDrawable(0));
//
//    }

    private View getPopupWindowContentView(final Context mContext, final PopupWindow mPopupWindow) {
        // 一个自定义的布局，作为显示的内容
        int layoutId = R.layout.popup_content_layout;   // 布局ID
        View contentView = LayoutInflater.from(mContext).inflate(layoutId, null);
        View.OnClickListener menuItemOnClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), "Click " + ((TextView) v).getText(), Toast.LENGTH_SHORT).show();
                if (mPopupWindow != null) {
                    mPopupWindow.dismiss();
                }
            }
        };
        contentView.findViewById(R.id.menu_item1).setOnClickListener(menuItemOnClickListener);
        return contentView;
    }

    public void showPopupWindowKnowledgePoint(View anchorView,Context mContext,PopupWindow mPopupWindow) {
        View contentView = getPopupWindowContentView(mContext,mPopupWindow);
        mPopupWindow = new PopupWindow(contentView,
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        // 如果不设置PopupWindow的背景，有些版本就会出现一个问题：无论是点击外部区域还是Back键都无法dismiss弹框
        mPopupWindow.setBackgroundDrawable(new ColorDrawable());
        // 设置好参数之后再show
        int windowPos[] = PopupWindowUtil.calculatePopWindowPos(anchorView, contentView);
        int xOff = 20; // 可以自己调整偏移
        windowPos[0] -= xOff;
        mPopupWindow.showAtLocation(anchorView, Gravity.TOP | Gravity.START, windowPos[0], windowPos[1]);
    }


}
